package cn.wildfirechat.voipdemo;


import cn.hutool.json.JSONObject;
import cn.wildfirechat.pojos.OutputMessageData;
import cn.wildfirechat.voipdemo.call.CallService;
import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class Controller {
    @Autowired
    private ServiceImpl mService;

    private static final Logger LOG = LoggerFactory.getLogger(Controller.class);

    @PostMapping(value = "/robot/recvmsg", produces = "application/json;charset=UTF-8"   )
    public Object recvMsg(@RequestBody OutputMessageData messageData) {
        LOG.info("recv message {}", messageData);
        mService.onReceiveMessage(messageData);
        return "ok";
    }

    @GetMapping(value = "/robot/send/{cid}", produces = "application/json;charset=UTF-8"   )
    public Object send(@PathVariable String cid) {
        mService.StartPrivateCall(cid);
        return "ok";
    }

    @PostMapping(value = "/robot/sendCall", produces = "application/json;charset=UTF-8"   )
    public Object sendCall(@RequestBody JSONObject jsonStr) {
        mService.sendCall(jsonStr);
        return "ok";
    }

    @PostMapping(value = "/robot/recvmsg/conference", produces = "application/json;charset=UTF-8"   )
    public Object recvConferenceEvent(@RequestBody String event) {
        LOG.info("recv conference event {}", event);
        mService.onReceiveConferenceEvent(event);
        return "ok";
    }
}
